import 'package:flutter/material.dart';
import 'package:niuniu/pages/login/user_agreement/controller.dart';
import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';

class UserAgreementPage extends GetView<UserAgreementController> {
  const UserAgreementPage({Key? key}) : super(key: key);

  // 主视图
  Widget buildView() {
    return Center(
        child: WebViewWidget(
            controller: WebViewController()
              ..setJavaScriptMode(JavaScriptMode.unrestricted)
              ..setBackgroundColor(const Color(0x00000000))
              ..setNavigationDelegate(
                NavigationDelegate(
                  onProgress: (int progress) {
                    // Update loading bar.
                  },
                  onPageStarted: (String url) {},
                  onPageFinished: (String url) {},
                  onWebResourceError: (WebResourceError error) {},
                  // onNavigationRequest: (NavigationRequest request) {
                  //   if (request.url.startsWith('https://www.youtube.com/')) {
                  //     return NavigationDecision.prevent;
                  //   }
                  //   return NavigationDecision.navigate;
                  // },
                ),
              )
              ..loadRequest(
                  Uri.parse('https://www.ixigua.com/user_agreement'))));
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<UserAgreementController>(
      init: UserAgreementController(),
      id: "user_agreement",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("用户协议")),
          body: SafeArea(
            child: buildView(),
          ),
        );
      },
    );
  }
}
